package org.springsource.domain;

import java.io.Serializable;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonManagedReference;


@Entity
@Table(name = "AccountCategory")
@AssociationOverrides({
	@AssociationOverride(name = "pk.account", 
		joinColumns = @JoinColumn(name = "account_id")),
	@AssociationOverride(name = "pk.category", 
		joinColumns = @JoinColumn(name = "category_id")) })
public class AccountCategory implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3004743721361603500L;
	private AccountCategoryId pk = new AccountCategoryId();
	private String createdBy;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(nullable=false)
	private Long id;
	public AccountCategory(){
		
	}
	@EmbeddedId
	public AccountCategoryId getPk() {
		return pk;
	}

	public void setPk(AccountCategoryId pk) {
		this.pk = pk;
	}
	@Transient
	public Category getCategory(){
		return this.getPk().getCategory();
	}
	
	public void setCategory(Category category){
		this.getPk().setCategory(category);
	}
	@Transient
	@JsonManagedReference("categories")
	public Account getAccount(){
		return this.getPk().getAccount();
	}
	
	public void setAccount(Account account){
		this.getPk().setAccount(account);
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;
 
		AccountCategory that = (AccountCategory) o;
 
		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;
 
		return true;
	}
 
	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}

}
